package model

import (
	"rikao2/rikao2rpc/rikao2rpc"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Phone    string `json:"Phone"`
	Password string `json:"Password"`
}

type Shops struct {
	gorm.Model
	UserId int    `json:"UserId"`
	Title  string `json:"Title"`
}

func (u *User) ShopList(db *gorm.DB, lists []*rikao2rpc.ShopList, in *rikao2rpc.ListRequest) ([]*rikao2rpc.ShopList, error) {

	err1 := db.Debug().Model(&User{}).Select("shops.*,shops.id as shops_id,users.phone,users.password").
		Joins("left join shops on shops.id=users.shop_id").
		Scopes(Paginate(int(in.Page), int(in.Size))).Find(&lists).Error

	return lists, err1

}
